﻿using CToolsWin.DAL.sys;
using Common.Extend;
using Model.sys;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CToolsWin.BLL.sys
{
    public class BLLSqlConn
    {
        private DALSqlConn dal = new DALSqlConn();
        /// <summary>
        /// 初始化表
        /// </summary>
        public bool InitTable()
        {
            try
            {
                bool bol = dal.InitTable();
                return bol;
            }
            catch (Exception ex)
            {
                Common.Msg.Log.GetLog.Error("初始化表【sys_SqlConn】时发生异常", ex);
                return false;
            }
        }
        public bool IsExists(sys_SqlConn m)
        {
            try
            {
                return dal.IsExists(m);
            }
            catch (Exception ex)
            {
                Common.Msg.Log.GetLog.Error("检查【sys_SqlConn】是否存在【Name】" + m.Name + "或【Code】" + m.Code + "时发生异常", ex);
                return false;
            }
        }
        public long Add(sys_SqlConn m)
        {
            try
            {
                bool bol = dal.IsExists(m);
                if (bol == false)
                    return dal.Add(m);
            }
            catch (Exception ex)
            {
                Common.Msg.Log.GetLog.Error("添加数据库连接信息异常", ex);
            }
            return 0;
        }
        public bool Update(sys_SqlConn m)
        {
            try
            {
                bool bol = dal.IsExists(m);
                if (bol == false)
                    return dal.Update(m, null);
            }
            catch (Exception ex)
            {
                Common.Msg.Log.GetLog.Error("保存数据库连接信息异常", ex);
            }
            return false;
        }
        public List<sys_SqlConn> GetList(sys_SqlConn m)
        {
            return dal.GetListByPage(new Common.DB.Paging(1, 20, "ID"), m).ExToList<sys_SqlConn>();
        }
    }
}
